def success_response(data=None, message='操作成功', code=200):
    """成功响应格式 - Flask-RESTX兼容版本"""
    response = {
        'code': code,
        'message': message,
        'data': data
    }
    return response, code


def error_response(message='操作失败', code=400, data=None):
    """错误响应格式 - Flask-RESTX兼容版本"""
    response = {
        'code': code,
        'message': message,
        'data': data
    }
    return response, code


def paginate_response(query, page, per_page, total=None):
    """分页响应格式 - Flask-RESTX兼容版本"""
    if total is None:
        total = query.count()
    
    items = query.offset((page - 1) * per_page).limit(per_page).all()
    
    data = {
        'list': [item.to_dict() if hasattr(item, 'to_dict') else item for item in items],
        'pagination': {
            'page': page,
            'per_page': per_page,
            'total': total,
            'pages': (total + per_page - 1) // per_page
        }
    }
    
    return success_response(data) 